package cn.pn.project.mapper.base;
import cn.pn.project.pojo.base.Coupon;
import cn.pn.project.pojo.commodity.Commodity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface CouponDao {
    /**
     * 通过优惠券id查询优惠券信息
     * @param couponId
     * @return
     */
    @Select("SELECT * FROM pn_base.Coupon WHERE couponId=#{couponId};")
    Coupon findByCouponId(@Param("couponId") Integer couponId) throws Exception;


    /**
     * 获取商品以及该商品下的优惠券
     * @param commodity 需要获取到商品的id和大类型
     * @return
     */
    @Select("SELECT * FROM coupon WHERE couponType =1 AND releId = #{typeId} OR couponType =2 AND releId =#{commodityId}")
    /**
     * 抽奖添加优惠券
     */
    List<Coupon> findAllByCouponTypeAndReleId(@Param("typeId")Integer typeId,@Param("commodityId")Integer commodityId)throws Exception;


    /**
     * 获取所有当前未过期的优惠券
     * @return
     * @throws Exception
     */
    @Select("SELECT * FROM `coupon` WHERE STATUS=1")
    List<Coupon> findAllCoupon()throws  Exception;
}
